// miniprogram/pages/profile-weather/profile-weather.js
import {
  weekEnum as weekday,
  airQuailtyLevel,
  arrForAirColor,
  lifeIndexEnum,
  iconType,
  rainType,
  snowType
} from '../../utils/utils'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    backImgUrl: 'https://7778-wx-lcy-001-7c4596-1258768646.tcb.qcloud.la/cloud.jpg?sign=c2ae35f4801b87899b6699469b943367&t=1552072527',
    location: {
      x: '116.40',
      y: '39.9',
      name: '北京市'
    },
    position: '正在获取位置...',
    todayData: {},
    tomorrowData: {},
    everyHourData: [],
    everyWeekData: [],
    airQuality: {},
    liveWeather: {},
    lifeStyle: [],
    // lifeEnum: lifeEnum,
    iconType: iconType,
    warmPrompt: '',
    width: 0,
    canvasHeight: 320,
    scole: 0,
    canvas_instance: null,
    apl: 0,
    rain_ins: null,
    snow_ins: null
  },
  chooseLoCation() {},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    wx.getSystemInfo({
      success: (res)=> {
        this.setData({
          width: res.windowHeight,
          height:res.windowWidth/375,
          canvas_instance: wx.createCanvasContext('animation', this)
        })
      },
    })
    this.getPosition()
  },
  getPosition(){
    wx.getLocation({
      type:'gcj02',
      success: this.updateLocation,
      fail:err => {
        console.log(err)
      }
    })
  },
  updateLocation(res){
    if(this.data.rain_ins){
      this.data.rain_ins.stop();
    }
    if(this.data.snow_ins){
      this.data.snow_ins.stop();
    }
    let {lotitude:x,longitude:y,name} = res;
    let data = {
      location:{
        x,y,
        name: name || '北京市'
      },
      rain_ins:null,
      snow_ins:null
    };
    this.setData(data)
    // this.getLocation(x,y,name)
  },
  getLocation(){
    wx.showModal({
      title: '定位中。。。',
      mask:true
    })

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})